package com.ruyuan.eshop.common.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 渠道枚举
 *
 * @author zhonghuashishan
 * @version 1.0
 */
public enum ChannelEnum {

    /**
     * 儒猿生鲜，自营
     */
    SELF(1, "儒猿生鲜"),

    /**
     * 美团
     */
    MEITUAN(2, "美团"),

    /**
     * 饿了么
     */
    ELEME(3, "饿了么"),

    /**
     * 淘鲜达
     */
    TAOXIANDA(4, "淘鲜达"),

    /**
     * 招商银行 China Merchants Bank
     */
    CMB(5, "招商银行");

    private Integer code;

    private String value;

    ChannelEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static Map<Integer, String> toMap(){
        Map<Integer, String> map = new HashMap<>(16);
        for (ChannelEnum element : ChannelEnum.values() ){
            map.put(element.getCode(),element.getValue());
        }
        return map;
    }

    public static ChannelEnum getByCode(Integer code){
        if(code == null) {
            return null;
        }
        for(ChannelEnum element : ChannelEnum.values()){
            if (code.equals(element.getCode())) {
                return element;
            }
        }
        return null;
    }

}